package cn.structure.edp;

import cn.structure.BaseEntity;
import cn.structure.ClassEntity;
import cn.structure.ConstructorCallEntity;

import java.util.Objects;

public class CreateObject extends EdpEntity {
    private BaseEntity creationSite;    // 创建点的父级，可能是变量、方法
    private ClassEntity typeToCreate;
    private ConstructorCallEntity objectCreated;

    public CreateObject(BaseEntity creationSite, ClassEntity typeToCreate, ConstructorCallEntity objectCreated) {
        super();
        this.creationSite = creationSite;
        this.typeToCreate = typeToCreate;
        this.objectCreated = objectCreated;
    }

    public enum Role {
        creationSite, typeToCreate, objectCreated
    }

    public BaseEntity getCreationSite() {
        return creationSite;
    }

    public void setCreationSite(BaseEntity creationSite) {
        this.creationSite = creationSite;
    }

    public ClassEntity getTypeToCreate() {
        return typeToCreate;
    }

    public void setTypeToCreate(ClassEntity typeToCreate) {
        this.typeToCreate = typeToCreate;
    }

    public ConstructorCallEntity getObjectCreated() {
        return objectCreated;
    }

    public void setObjectCreated(ConstructorCallEntity objectCreated) {
        this.objectCreated = objectCreated;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("CreateObject{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"creationSite\":")
                .append(creationSite);
        sb.append(",\n\t\"typeToCreate\":")
                .append(typeToCreate);
        sb.append(",\n\t\"objectCreated\":")
                .append(objectCreated);
        sb.append("\n}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CreateObject that = (CreateObject) o;
        return Objects.equals(creationSite, that.creationSite) &&
                Objects.equals(typeToCreate, that.typeToCreate) &&
                Objects.equals(objectCreated, that.objectCreated);
    }

    @Override
    public int hashCode() {
        return Objects.hash(creationSite, typeToCreate, objectCreated);
    }
}
